<?php


namespace Modules\Common\Helpers\Traits\Models;


use Illuminate\Support\Facades\Storage;

trait Attribute {

    public function getImagesUrlAttribute($key){
        return $this->addPrefixToImgArray($this->images);
    }

    public function getAvatarUrlAttribute($key) {
        return $this->addPrefixToImg($this->avatar);
    }




    public function getImageUrlAttribute($key) {
        return $this->addPrefixToImg($this->image);
        return Storage::disk('temp')->url($this->image);
    }

    public function getCoverUrlAttribute($key) {
        return $this->addPrefixToImg($this->cover);
        return Storage::disk('temp')->url($this->cover);
    }

    public function getIdCardImgUrlAttribute($key) {
        return $this->addPrefixToImg($this->id_card_img);
        return Storage::disk('temp')->url($this->id_card_img);
    }

    public function getIdCardBackImgUrlAttribute($key) {
        return $this->addPrefixToImg($this->id_card_back_img);
        return Storage::disk('temp')->url($this->id_card_back_img);
    }

    public function getProofOfSkillsImgUrlAttribute($key) {
        // dd(
        //     $this->proof_of_skills_img,
        //     gettype($this->proof_of_skills_img)
        // );
        // return $this->proof_of_skills_img;
        return $this->addPrefixToImgArray($this->proof_of_skills_img);

        return Storage::disk('temp')->url($this->proof_of_skills_img);
    }

    public function getOtherProofImgUrlAttribute($key) {
        return $this->addPrefixToImgArray($this->other_proof_img);
        return Storage::disk('temp')->url($this->other_proof_img);
    }

    public function getDeedImgUrlAttribute($key) {
        return $this->addPrefixToImgArray($this->deed_img);

        return Storage::disk('temp')->url($this->deed_img);
    }

    public function getIconUrlAttribute($key) {
        return $this->addPrefixToImg($this->icon);
        return Storage::disk('temp')->url($this->icon);
    }

    public function getBusinessLicenseImgUrlAttribute($key) {

        return $this->addPrefixToImgArray($this->business_license_img);
        return Storage::disk('temp')->url($this->business_license_img);
    }

    public function getLegalPersonIdCardImgUrlAttribute($key) {
        return $this->addPrefixToImg($this->legal_person_id_card_img);
        return Storage::disk('temp')->url($this->legal_person_id_card_img);
    }

    public function getLegalPersonIdCardBackImgUrlAttribute($key) {
        return $this->addPrefixToImg($this->legal_person_id_card_back_img);
        return Storage::disk('temp')->url($this->legal_person_id_card_back_img);
    }

    public function getRelatedQualificationsImgUrlAttribute($key) {

        return $this->addPrefixToImgArray($this->related_qualifications_img);
        return Storage::disk('temp')->url($this->related_qualifications_img);
    }

    public function getPhotoUrlAttribute($key) {
        return $this->addPrefixToImg($this->photo);
        return Storage::disk('temp')->url($this->photo);
    }

    private function addPrefixToImgArray($images = []) {
        if (is_null($images) || !is_array($images)) {
            return [];
        }
        foreach ($images as $key => $value) {
            $images[$key] = Storage::disk('temp')->url($value);
        }
        // // dd($aa);
        return $images;
    }

    private function addPrefixToImg($img) {
        if (is_null($img) || strlen($img) == 0) {
            return '';
        }

        return Storage::disk('temp')->url($img);
    }
}
